﻿@using CleanArchitecture.Blazor.Server.UI.Services.JsInterop
<div class="d-flex justify-content-between">
    <div class="d-flex align-center gap-2">
        <MudBreadcrumbs Items="@BreadcrumbItems"></MudBreadcrumbs>
    </div>
    <MudSpacer></MudSpacer>
    <div class="d-flex align-center gap-1">

        @if (OnSaveButtonClick.HasDelegate)
        {
            <MudLoadingButton Loading="@Saving"  OnClick="@Save">@ConstantString.Save</MudLoadingButton>
        }
        @if (OnGoEditClick.HasDelegate)
        {
            <MudButton OnClick="@GoEdit">@ConstantString.Edit</MudButton>
        }
        @if (OnDeleteClick.HasDelegate || OnPrintClick.HasDelegate)
        {
            <MudMenu Icon="@Icons.Material.Filled.MoreVert" AnchorOrigin="Origin.BottomLeft"
                     AriaLabel="@ConstantString.More">
                @if (OnDeleteClick.HasDelegate)
                {
                    <MudMenuItem OnClick="Delete"> @ConstantString.Delete</MudMenuItem>
                }
                @if (OnPrintClick.HasDelegate)
                {
                    <MudMenuItem OnClick="Print"> @ConstantString.Print</MudMenuItem>
                }
            </MudMenu>
        }

    </div>
</div>

@code {
    [Parameter]
    public List<BreadcrumbItem>? BreadcrumbItems { get; set; }
    [Parameter]
    public bool Saving { get; set; }
    [Parameter]
    public EventCallback OnSaveButtonClick { get; set; }
    [Parameter]
    public EventCallback OnGoEditClick { get; set; }
    [Parameter]
    public EventCallback OnDeleteClick { get; set; }
    [Parameter]
    public EventCallback OnPrintClick { get; set; }

    private async Task GoBack()
    {
        await new HistoryGo(JS).GoBack();
    }

    private async Task Save()
    {
        if (OnSaveButtonClick.HasDelegate)
        {
            await OnSaveButtonClick.InvokeAsync();
        }
    }
    private async Task GoEdit()
    {
        if (OnGoEditClick.HasDelegate)
        {
            await OnGoEditClick.InvokeAsync();
        }
    }
    private async Task Delete()
    {
        if (OnDeleteClick.HasDelegate)
        {
            await OnDeleteClick.InvokeAsync();
        }
    }
    private async Task Print()
    {
        if (OnPrintClick.HasDelegate)
        {
            await OnPrintClick.InvokeAsync();
        }
    }
}
